package cc.sunni.admin.controller;

import cc.sunni.admin.service.FriendLinkService;
import cc.sunni.api.BaseController;
import cc.sunni.api.controller.admin.FriendLinkControllerApi;
import cc.sunni.common.utils.R;
import cc.sunni.pojo.bo.SaveFriendLinkBO;
import cc.sunni.pojo.mo.FriendLinkMO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class FriendLinkController extends BaseController implements FriendLinkControllerApi {
    @Autowired
    private FriendLinkService friendLinkService;

    @Override
    public R saveOrUpdateFriendLink(@Validated SaveFriendLinkBO saveFriendLinkBO) {
        // saveFriendLinkBO -> ***MO
        FriendLinkMO saveFriendLinkMO = new FriendLinkMO();
        BeanUtils.copyProperties(saveFriendLinkBO, saveFriendLinkMO);
        saveFriendLinkMO.setCreateTime(new Date());
        saveFriendLinkMO.setUpdateTime(new Date());
        friendLinkService.saveOrUpdateFriendLink(saveFriendLinkMO);
        return R.ok();
    }

    @Override
    public R getFriendLinkList() {
        return R.ok(friendLinkService.queryAllFriendLinkList());
    }

    @Override
    public R delete(String linkId) {
        friendLinkService.delete(linkId);
        return R.ok();
    }

    @Override
    public R queryPortalAllFriendLinkList() {
        List<FriendLinkMO> list = friendLinkService.queryPortalAllFriendLinkList();
        return R.ok(list);
    }
}
